package cn.lds.j367.dsbank.common.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

public class MD5Utils {

    public static String md5(String sourcMMr){

        MessageDigest md = null;
        StringBuilder sbuilder = new StringBuilder("");
        try {
            //获取一个摘要算法对象
            md = MessageDigest.getInstance("MD5");

            //使用自定的字节数组获得更新摘要
            md.update(sourcMMr.getBytes());

            //获得密文
            byte[] digest = md.digest();

//            System.out.println(Arrays.toString(digest));
            int i;


            for (int offset = 0; offset < digest.length; offset++) {
                i = digest[offset];
                if (i < 0){
                    i += 256;
                }
                if (i < 16){
                    sbuilder.append("0");
                }
                //将一个数字转换为该数字的16进制表现形式
                sbuilder.append(Integer.toHexString(i));
            }


        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }

        return sbuilder.toString();

    }
}
